package com.pocketsweet.ui.uilib.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.pocketsweet.R;
import com.pocketsweet.model.MLUser;

/**
 * 
 * @author Kam
 * 
 */
public class TaskAdapter extends BaseListAdapter<MLUser> {
	public TaskAdapter(Context ctx) {
		super(ctx);
	}

	public TaskAdapter(Context ctx, List<MLUser> datas) {
		super(ctx, datas);
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item_task, parent, false);
			viewHolder = new ViewHolder(convertView);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		viewHolder.refreshView(datas.get(position), position);
		return convertView;
	}

	private class ViewHolder implements View.OnClickListener {
		TextView tvTaskTitle;
		TextView tvTaskStatus;
		TextView tvStatus;
		TextView tvInfo;
		TextView tvReward;
		MLUser item;
		private View parent;

		private ViewHolder(View parent) {
			this.parent = parent;
			initView(parent);
		}

		public void initView(View parent) {
			tvTaskTitle = (TextView) parent.findViewById(R.id.tvTaskTitle);
			tvTaskStatus = (TextView) parent.findViewById(R.id.tvTaskStatus);
			tvStatus = (TextView) parent.findViewById(R.id.tvStatus);
			tvInfo = (TextView) parent.findViewById(R.id.tvStar);
			tvReward = (TextView) parent.findViewById(R.id.tvReward);
		}

		public void refreshView(MLUser item, int i) {
			this.item = item;
			tvStatus.setOnClickListener(this);
		}

		@Override
		public void onClick(View v) {
			if (v.equals(tvStatus)) {
				// TODO
			}
		}

	}
}
